package com.bjpowernode.controller;

import jakarta.annotation.Resource;
import org.springframework.ai.image.ImageModel;
import org.springframework.ai.image.ImagePrompt;
import org.springframework.ai.image.ImageResponse;
import org.springframework.ai.openai.OpenAiImageOptions;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class ImageController {

    @Resource
    private ImageModel imageModel;

    @RequestMapping("/ai/image")
    public Object image(@RequestParam("msg") String msg) {
        ImageResponse imageResponse = imageModel.call(new ImagePrompt(msg));
        System.out.println(imageResponse);

        String imageUrl = imageResponse.getResult().getOutput().getUrl();
        // todo 图片处理逻辑

        return imageResponse.getResult().getOutput();
    }

    @RequestMapping("/ai/image2")
    public Object image2(@RequestParam("msg") String msg) {
        ImageResponse imageResponse = imageModel.call(new ImagePrompt(msg,
                OpenAiImageOptions.builder()
                        .withQuality("hd")  // 高清图像
                        .withN(1)   // 生成1张图片
                        .withHeight(1024)   // 生成的图片高度
                        .withWidth(1024)    // 生成的图片宽度
                        .build()
        ));
        System.out.println(imageResponse);
        return imageResponse.getResult().getOutput();
    }

}
